/*************************************************************************
	> File Name: oj-119_yesterday_tomorrow.c
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年10月29日 星期四 15时34分18秒
 ************************************************************************/

#include <stdio.h>
int month[13] = {
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
int isleap(int y) {
    if ((y % 4 == 0 && y % 100) || y % 400 == 0) {
        return 1;
    }
    return 0;
}
int main() {
    int y, m, d;
    scanf("%d%d%d", &y, &m, &d);
    if (isleap(y)) month[2]++;
    int yd = d - 1, td = d + 1;
    int yy = y, ty = y, ym = m, tm = m;
    if (yd < 1) {
        ym = m - 1;
        if (ym < 1) yy = y - 1, ym = 12;
        yd = month[ym];
    }
    printf("%d %d %d\n", yy, ym, yd);
    if (td > month[m]) {
        td = 1;
        tm = m + 1;
        if (tm > 12) ty = y + 1, tm = 1;
    }
    printf("%d %d %d", ty, tm, td);
    return 0;
}
